<?php
	session_unset();
	session_start();
	require_once('../inc/fnc.php');
	require_once('../inc/conn.php');
	require_once('../inc/settings.php');

	//Set values
	$fbid = $_GET['id'];
	$email = $_GET['email'];
	$fname = $_GET['fname'];
	$lname = $_GET['lname'];

	///Merging previous account and FB account
	$query = "UPDATE `users` SET `fbuid` = {$fbid}, `fname` = '{$fname}', `lname` = '{$lname}', `email varification` = 'Y' WHERE `email` = '{$email}' AND `delete flag` = 'N' LIMIT 1";
	$result = mysql_query($query, $connection);
	
	//Now get userid and username to be used for the session
	$query = "SELECT `userid` FROM `users` WHERE `email` = '{$email}' AND `delete flag` = 'N' LIMIT 1";
	$resultset = mysql_query($query, $connection);

	//Now log in user
	$_SESSION['login'] = TRUE;

	$row = mysql_fetch_array($resultset);
	$_SESSION['user'] = getUsername($row['userid']);
	$_SESSION['userId'] = $row['userid'];

	$return['status'] = true;

	echo json_encode($return);

?>